package com.xdqzy.baseline.demo.converter;

import com.xdqzy.baseline.common.converter.AbstractBizConverter;
import com.xdqzy.baseline.demo.constant.ProductConstants;
import com.xdqzy.baseline.demo.model.ProductTypeModel;
import com.xdqzy.baseline.demo.service.ProductTypeService;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

/**
 * @author : winter
 * @version V1.0
 * @Title: 商品类型转换器
 * @ClassName : com.xdqzy.baseline.demo.converter.ProductTypeConverter.java
 * @Description :
 * @date :  2020-11-15 23:17
 */
@Component
public class ProductTypeConverter extends AbstractBizConverter<String, ProductTypeModel> {

    @Resource
    private ProductTypeService productTypeService;

    @Override
    protected String getBizModule() {
        return ProductConstants.PRODUCT_TYPE_COMBINE;
    }

    @Override
    protected Map<String, ProductTypeModel> queryConvertDataByIds(Set<String> ids, boolean useCache) {
        //此处的id为商品类型编码
        return productTypeService.lambdaQuery().in(ProductTypeModel::getTypeCode, ids).list().stream().collect(Collectors.toMap(ProductTypeModel::getTypeCode, p -> p));
    }
}
